package com.service.business.utils;

import com.service.core.exception.CommonException;
import com.service.utility.aes.AesUtil;
import org.apache.commons.lang3.StringUtils;

/**
 * <dl>
 * <dt>platform</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2018</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019-04-07</dd>
 * </dl>
 */
public class PwdUtils {


    public static String aesToMd5(String aesPwd, String salt) {
        String pwd = AesUtil.deCode(aesPwd, AesUtil.DEFAULT_KEY);
        return Md5Utils.encryptPassword(Md5Utils.hash(pwd), salt);
    }

    public static void isValidSafetyPwd(String pwd) {
        String decodePwd = AesUtil.deCode(pwd, AesUtil.DEFAULT_KEY);
        if (!StringUtils.isNumeric(decodePwd) || decodePwd.length() < 6) {
            throw new CommonException("修改密码失败，支付密码必须为6位数字", "modify_pass_fail_pwd_is_not_numeric");
        }
    }

    public static String passwordToMd5(String pwd, String salt) {
        return Md5Utils.encryptPassword(Md5Utils.hash(pwd), salt);
    }

    public static void main(String[] args) {
        System.out.println(passwordToMd5("123456", "5c8"));
    }
}
